require 'fastercsv'
class OFACImporter
  BASE_URL = "www.treas.gov"
  BASE_PATH = "/offices/enforcement/ofac/sdn/delimit/"
  LISTS = [NameList.new, AddressList.new, AlternateNameList.new]
  
  def self.import_all
    LISTS.each do |list|
      import list
    end
  end
  
  def self.import list
    csv = Net::HTTP.get(BASE_URL, "#{BASE_PATH}#{list.sdn_name}.csv")
    csv.gsub!(/-0- /,'')
    values = FasterCSV.parse(csv[0..-2])    
    options = { :validate => false }
    columns = list.columns_in_order
    list.active_record_class.import columns, values, options
  end
  
end